export default function formTime(getType, outType, time) {
    let get = getType.toLocaleLowerCase();
    let out = outType.toLocaleLowerCase();
    let date;
    /**
     * 输入判断
     */
    switch (true) {
        // 时间戳秒
        case (get === "timestamp-s"):
            date = new Date(time * 1000);
            break;
            // 时间戳毫秒
            // 长时间格式
            // 短时间格式
        case (get === "timestamp-ms" || get === "yyyy-mm-dd hh:mm:ss" || get === "yyyy-m-d h:m:s"): {
            date = new Date(time);
        }
        break;
        // 长时间中文
        // 短时间中文
    case (get === "yyyy-mm-dd hh:mm:ss-s" || get === "yyyy-m-d h:m:s-s"): {
        let str = time;
        // str = str.replace( /\s/g,'')
        str = str.replace(/[^0-9]/g, ',')
        let timeArr = str.split(",")
        time = timeArr[0] + '-' + timeArr[1] + '-' + timeArr[2] + ' ' + timeArr[4] + ':' + timeArr[5] + '-' + timeArr[6]
        date = new Date(time);
    }
    // 短时间中文
    break;
    default:
        console.error("输入时间转换格式不正确");
        console.error(getType)
        break;
    }
    /**
     * 输出判断
     */
    let result;
    let timestampS = date.getTime() / 1000;
    let timestampMS = date.getTime();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    let hour = date.getHours();
    let minute = date.getMinutes();
    let second = date.getSeconds();
    switch (true) {
        // 时间戳秒
        case (out === "timestamp-s"):
            result = timestampS
            break;
            // 时间戳毫秒
        case (out === "timestamp-ms"):
            result = timestampMS;
            break;
            // 长时间格式
        case (out === "yyyy-mm-dd hh:mm:ss"):
            result = year + '-' + (month >= 10 ? month : '0' + month) + '-' + (day >= 10 ? day : '0' + day) + ' ' + (hour >= 10 ? hour : '0' + hour) + ':' + (minute >= 10 ? minute : '0' + minute) + ':' + (second >= 10 ? second : '0' + second)
            break;
            // 短时间格式
        case (out === "yyyy-m-d h:m:s"):
            result = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
            break;
            // 长时间中文
        case (out === "yyyy-mm-dd hh:mm:ss-s"):
            result = year + '年' + (month >= 10 ? month : '0' + month) + '月' + (day >= 10 ? day : '0' + day) + '日 ' + (hour >= 10 ? hour : '0' + hour) + '时' + (minute >= 10 ? minute : '0' + minute) + '分' + (second >= 10 ? second : '0' + second) + '秒'
            break;
            // 短时间中文
        case (out === "yyyy-m-d h:m:s-s"):
            result = year + '年' + month + '月' + day + '日 ' + hour + '时' + minute + '分' + second + '秒';
            break;
        default:
            console.error("输出时间转换格式不正确");
            console.error(outType)
            break;
    }
    return result
}